package com.practice;

import java.util.Scanner;

/**
 * 需求：设计一个带参数的方法实现求1到n之间的偶数和
 */
public class Demo2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数");
        int n = sc.nextInt();
        System.out.println(getEvenSum(n));
    }

    public static int getEvenSum(int n) {
        int sum = 0;
        for (int i = 0; i <= n; i++) {
            if (i % 2 == 0) {
                sum += i;
            }
        }
        return sum;
    }
}
